﻿
Imports System.ServiceModel
Imports LibMedienverwaltung.Services.Amazon

Namespace Services

    Public Class AmazonDataService

        Private _accessKeyId As String
        Private _secretKey As String
        Private _endpointAddress As String

        Protected WithEvents _client As LibMedienverwaltung.Amazon.AWSECommerceServicePortTypeClient

        Public Sub New(ByVal accessKeyId As String, ByVal secretKey As String, ByVal endpointAddress As String)
            _accessKeyId = accessKeyId
            _secretKey = secretKey
            _endpointAddress = endpointAddress

            Call InternalInitialize()

        End Sub
        
        Public ReadOnly Property AccessKeyId As String
        	Get
        		Return _accessKeyId 
        	End Get
        End Property
        
        Protected Overridable Sub InternalInitialize()

            Dim binding As New BasicHttpBinding(BasicHttpSecurityMode.Transport)

            binding.MaxReceivedMessageSize = Integer.MaxValue

            _client = New LibMedienverwaltung.Amazon.AWSECommerceServicePortTypeClient(binding, New EndpointAddress(_endpointAddress))

            _client.ChannelFactory.Endpoint.Behaviors.Add(New AmazonSigningEndpointBehavior(_accessKeyId, _secretKey))



        End Sub

        Public Overridable Function RequestWait(ByVal itemSearch As LibMedienverwaltung.Amazon.ItemSearch) As LibMedienverwaltung.Amazon.ItemSearchResponse
            Return _client.ItemSearch(itemSearch)
        End Function



    End Class

End Namespace